<!DOCTYPE html>
<html>

	<head>
		<meta charset="utf-8">
		<meta name="renderer" content="webkit">
		<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
		<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
		<meta name="apple-mobile-web-app-status-bar-style" content="black">
		<meta name="apple-mobile-web-app-capable" content="yes">
		<meta name="format-detection" content="telephone=no">
		<meta http-equiv="Cache-Control" content="no-siteapp">
		<link rel="stylesheet" href="../../../layui/css/layui.css" media="all" />
		<link rel="stylesheet" href="../../../css/public.css" media="all" />
	</head>

	<body class="childrenBody">
		<form class="layui-form" lay-filter="formTest" id="form" style="width: 80%;">
			<div class="layui-form-item layui-row layui-col-xs12">
				<label class="layui-form-label">报废设备</label>
				<div class="layui-input-block">
					<select id="did" name="did" lay-filter="did" lay-search>
						<option value="">请选择</option>
					</select>
				</div>
			</div>
			<div class="layui-form-item layui-row layui-col-xs12">
				<label class="layui-form-label">设备名</label>
				<div class="layui-input-block">
					<input disabled type="text" class="layui-input layui-disabled" id="name" name="name" lay-verify="required|size"
					 maxsize="50" placeholder="">
				</div>
			</div>
			<div class="layui-form-item layui-row layui-col-xs12">
				<label class="layui-form-label">品牌</label>
				<div class="layui-input-block">
					<input disabled type="text" class="layui-input layui-disabled" id="brand" name="brand" lay-verify="required|size"
					 maxsize="100" placeholder="">
				</div>
			</div>
			<div class="layui-form-item layui-row layui-col-xs12">
				<label class="layui-form-label">型号</label>
				<div class="layui-input-block">
					<input disabled type="text" class="layui-input layui-disabled" id="model" name="model" lay-verify="required|size"
					 maxsize="100" placeholder="">
				</div>
			</div>

			<div class="layui-form-item layui-row layui-col-xs12">
				<label class="layui-form-label">登记人</label>
				<div class="layui-input-block">
					<input disabled type="text" class="layui-input layui-disabled" id="creator" name="creator" lay-verify="required|size"
					 maxsize="100" placeholder="">
				</div>
			</div>

			<div class="layui-form-item layui-row layui-col-xs12">
				<label class="layui-form-label">登记时间</label>
				<div class="layui-input-block">
					<input disabled type="text" class="layui-input layui-disabled" id="createtime" name="createtime" lay-verify="required|size"
					 maxsize="100" placeholder="">
				</div>
			</div>

			<div class="layui-form-item layui-row layui-col-xs12">
				<label class="layui-form-label">备注</label>
				<div class="layui-input-block">
					<textarea placeholder="" class="layui-textarea" name="scrapremarks"></textarea>
				</div>
			</div>

			<div class="layui-form-item layui-row layui-col-xs12">
				<div class="layui-input-block">
					<button type="button" class="layui-btn layui-btn-sm" lay-submit="" lay-filter="submit">提交</button>
					<button type="button" class="layui-btn layui-btn-sm layui-btn-primary close-btn">取消</button>
				</div>
			</div>
		</form>
		<script type="text/javascript" src="../../../js/jquery-2.1.1.min.js"></script>
		<script type="text/javascript" src="../../../layui/layui.js"></script>
		<script type="text/javascript" src="../../../custom/js/common.js"></script>
		<!-- <script type="text/javascript" src="../../../js/index.js"></script> -->
		<script type="text/javascript">
			layui.use(['form', 'laydate', 'layer'], function() {
				var form = layui.form;
				var laydate = layui.laydate;
				var layer = parent.layer === undefined ? layui.layer : top.layer,
					$ = layui.jquery;
				var toInsertApi = constant.baseUrl + "/device/devicescrap/toInsert";
				var insertApi = constant.baseUrl + "/device/devicescrap/insert";
				var insertMethod = "post";
				var url = insertApi;
				var method = insertMethod;

				var devices = new Array();

				loadAjax(toInsertApi, "get", null, function(response) {
					baseCallBack(response, function(response) {
						//把响应的json填充到表单里面
						if (response.data) {
							var tmp = ""
							for (data of response.data) {
								tmp += '<option value="' + data.id + '">' + data.code + '</option>';
								devices[data.id] = data;
							}
							$("#did").append(tmp);
						}
						form.render('select'); //刷新select选择框渲染
					});
				});


				//下拉框选中
				form.on('select(did)', function(data){
					if (devices) {
						var device = devices[data.value];
						if (device) {
							$("#name").val(device.dtname);
							$("#brand").val(device.dtbrand);
							$("#model").val(device.dtmodel);
							$("#creator").val(device.ucreator);
							$("#createtime").val(device.createtime);
						} else {
							$("#name").val("");
							$("#brand").val("");
							$("#model").val("");
							$("#creator").val("");
							$("#createtime").val("");
						}
					}
				});

				form.on("submit(submit)", function(data) {
					loadAjax(url, method, data.field, function(response) {
						baseCallBack(response, parentReloadCallBack);
					});
					return false;
				})
			})
		</script>
	</body>

</html>
